package com.cvtc29.www;

import java.text.DecimalFormat;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Main extends Activity {
	//** Called when the activity is first created. */ 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
      //Listen for button clicks 
    Button button = (Button)findViewById(R.id.B001);
    button.setOnClickListener(calcBMI);
    }
    private OnClickListener calcBMI= new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			 DecimalFormat nf = new DecimalFormat("0.00");
	    	 EditText fieldheight = (EditText)findViewById(R.id.E001);
	    	 EditText fieldweight = (EditText)findViewById(R.id.E002);
	    	 double height = Double.parseDouble(fieldheight.getText().toString())/100;
	    	 double weight = Double.parseDouble(fieldweight.getText().toString());
	    	 double BMI = weight / (height * height);
	    	 TextView result = (TextView)findViewById(R.id.T003);
	    	 result.setText(T004.setText(getString(R.string.S004)+nf.format(BMI)));
	    
	    	 //Give health advice 
	    	 TextView fieldsuggest = (TextView)findViewById(R.id.T004);
	    	 if(BMI>25){
	    		 fieldsuggest.setText(R.string.S003);
	    	 }else if(BMI<20){
	    		 fieldsuggest.setText(R.string.S002);
	    	 }else{
	    		 fieldsuggest.setText(R.string.S001);
			
		       }
	   }
	};      

    
    	 
    
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    
    }}
